package com.whu.MenuHub.controller;

import com.whu.MenuHub.domain.FoodFlavor;
import com.whu.MenuHub.exception.MenuHubException;
import com.whu.MenuHub.service.FoodFlavorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/foodflavor")
@Api(tags = "食品偏好信息管理API")
public class FoodFlavorController {
    @Autowired
    FoodFlavorService foodFlavorService;

    @GetMapping("/id/{id}")
    @ApiOperation("根据id获取食品口味偏好信息")
    public FoodFlavor getFoodflavorByID(@ApiParam("食品ID")@PathVariable Integer id){
        return foodFlavorService.getfalvorByFoodID(id);
    }

    @PostMapping("")
    @ApiOperation("新增一条食品口味偏好信息")
    @PreAuthorize("hasAnyAuthority('all')")
    public FoodFlavor InsertFoodflavor(@ApiParam("食品口味信息")@RequestBody FoodFlavor foodFlavor) throws MenuHubException {
        return foodFlavorService.insertFoodFalvor(foodFlavor);
    }

    @PutMapping("")
    @ApiOperation("修改一条食品口味偏好记录")
    @PreAuthorize("hasAnyAuthority('all')")
    public void updateFoodflavor(@ApiParam("食品口味信息")@RequestBody FoodFlavor foodFlavor) throws MenuHubException {
        foodFlavorService.updateFoodFlavor(foodFlavor);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除一条食品口味偏好记录")
    @PreAuthorize("hasAnyAuthority('all')")
    public void deleteFoodflavor(@ApiParam("食品ID")@PathVariable Integer id) throws MenuHubException {
        foodFlavorService.deleteFoodFlavorById(id);
    }
}
